package com.ruoyi.applyNews.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.news.domain.News;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applyNews.domain.Passnews;
import com.ruoyi.applyNews.service.IPassnewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * applyNewsController
 * 
 * @author 祁正
 * @date 2023-06-05
 */
@RestController
@RequestMapping("/applyNews/applyNews")
public class PassnewsController extends BaseController
{
    @Autowired
    private IPassnewsService passnewsService;


    //通过新闻发布
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:edit')")
    @PutMapping("/pass/{id}")
    public AjaxResult passApplyNews(@PathVariable int id){
        int i = passnewsService.passNewsApply(id);
        return AjaxResult.success(i>0);
    }

    //添加新闻到news表
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:edit')")
    @PostMapping("/pass")
    public AjaxResult passNews(@RequestBody News news){
        int i = passnewsService.addNews(news);
        return AjaxResult.success(i>0);
    }


    //驳回新闻发布
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:edit')")
    @PutMapping("/back/{id}")
    public AjaxResult backApplyNews(@PathVariable int id){
        int i = passnewsService.backNewsApply(id);
        return AjaxResult.success(i>0);
    }



    /**
     * 查询applyNews列表
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:list')")
    @GetMapping("/list")
    public TableDataInfo list(Passnews passnews)
    {
        startPage();
        List<Passnews> list = passnewsService.selectPassnewsList(passnews);
        return getDataTable(list);
    }

    /**
     * 导出applyNews列表
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:export')")
    @Log(title = "applyNews", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Passnews passnews)
    {
        List<Passnews> list = passnewsService.selectPassnewsList(passnews);
        ExcelUtil<Passnews> util = new ExcelUtil<Passnews>(Passnews.class);
        util.exportExcel(response, list, "applyNews数据");
    }

    /**
     * 获取applyNews详细信息
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(passnewsService.selectPassnewsById(id));
    }

    /**
     * 新增applyNews
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:add')")
    @Log(title = "applyNews", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Passnews passnews)
    {
        return toAjax(passnewsService.insertPassnews(passnews));
    }

    /**
     * 修改applyNews
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:edit')")
    @Log(title = "applyNews", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Passnews passnews)
    {
        return toAjax(passnewsService.updatePassnews(passnews));
    }

    /**
     * 删除applyNews
     */
    @PreAuthorize("@ss.hasPermi('applyNews:applyNews:remove')")
    @Log(title = "applyNews", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(passnewsService.deletePassnewsByIds(ids));
    }
}
